package org.kirhgoff.mathbot;

import org.junit.Assert;

import org.aicontest.PlanetWars;
import org.apache.commons.io.IOUtils;
import org.junit.Ignore;
import org.junit.Test;

public class BotTest {
	@Ignore
	@Test
	public void testGetRequiredForce () {
		PlanetWars pw = new PlanetWars (fixture("fixtures/required.txt"));
		final MathModule module = new MathModule (Gene.fromPropertyFile(BotTest.class.getResourceAsStream("simple.gene")));
		final World world = new World (pw, module);
		PlanetInfo planet = world.getMyPlanets().get(0);
		Assert.assertEquals (125, module.howMuchIsRequiredToCapture(world, planet, null));
	}
	
	@Test
	public void testOneStep() {
		PlanetWars pw = new PlanetWars (fixture("fixtures/crash.txt"));
		System.out.println("Starting round");
		try {
			MatematicBot.DoTurn(pw);
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Ignore
	@Test
	public void testWorld() throws Exception {
		PlanetWars pw = new PlanetWars (fixture("fixtures/small.txt"));
		final MathModule module = new MathModule (Properties.SIMPLE_GENE);
		final World world = new World (pw, module);
		System.out.println("\nWORLD:\n=======\n" + world);
		
		Assert.assertEquals (1, world.getEnemyFleetsCount ());
		Assert.assertEquals (4, world.getPlanetsCount ());
		Assert.assertEquals (1, world.getMyFleetsCount ());
		
		Assert.assertEquals (105, world.overallEnemyForce());
		Assert.assertEquals (20, world.myTotalAttackingForce());
	}

	public static String fixture(String fixture) {
		String fixtureFile;
		try {
			fixtureFile = IOUtils.toString(
					BotTest.class.getResourceAsStream(fixture));
		} catch (Exception e) {
			throw new RuntimeException (e);
		}
		return fixtureFile;
	}
}
